import requests
import execjs
cookies = {
    'Hm_lvt_f32803886966beff8fa513f7a33dea1e': '1733900502',
    'HMACCOUNT': 'D628B1163604AA31',
    'Hm_lpvt_f32803886966beff8fa513f7a33dea1e': '1733900517',
    'SUNWAY-ESCM-COOKIE': 'cb777c10-bec0-4e17-99f2-17b45ee8c20b',
    '__jsluid_s': '37b1fa0566ac3cb6ee4136180a0e1b51',
    'JSESSIONID': '93C67BAA85BD866C19FC72E9A3AB28AA',
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json',
    # 'Cookie': 'Hm_lvt_f32803886966beff8fa513f7a33dea1e=1733900502; HMACCOUNT=D628B1163604AA31; Hm_lpvt_f32803886966beff8fa513f7a33dea1e=1733900517; SUNWAY-ESCM-COOKIE=cb777c10-bec0-4e17-99f2-17b45ee8c20b; __jsluid_s=37b1fa0566ac3cb6ee4136180a0e1b51; JSESSIONID=93C67BAA85BD866C19FC72E9A3AB28AA',
    'Origin': 'https://ec.minmetals.com.cn',
    'Pragma': 'no-cache',
    'Referer': 'https://ec.minmetals.com.cn/open/home/purchase-info',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}


PublickKey = requests.post('https://ec.minmetals.com.cn/open/homepage/public', cookies=cookies, headers=headers).text
# print(PublickKey)

param = execjs.compile(open('./扣代码方式.js', 'r', encoding='utf-8').read()).call('main', PublickKey,99)

# print(param)
json_data = {
    'param': param
}

response = requests.post(
    'https://ec.minmetals.com.cn/open/homepage/zbs/by-lx-page',
    cookies=cookies,
    headers=headers,
    json=json_data,
)


for i in response.json()['list']:
    print(i['mc'])